package cn.gov.msa.collection;

import org.apache.log4j.Logger;

import cn.gov.msa.util.PropertiesTools;
import cn.gov.msa.util.WebServiceTools;
import net.sf.json.JSONObject;


public class SmsService {
	
	private static Logger logger = Logger.getLogger(SmsService.class);
	/**
	 * 单条短信发送
	 * @param phone 手机号码
	 * @param message 短信内容
	 * @return {"result":"1:成功/0:失败","info":"1:短信发送成功/0:失败原因", "batchId":"成功才会有短信发送批次号返回"}
	 */
	public static JSONObject sendSingleMessage(String phone, String message) {
		String url = PropertiesTools.readProperties("gahWS.url");
		String methods = PropertiesTools.readProperties("sms.method");
		
		JSONObject jsonObj = new JSONObject();
		jsonObj.put("phone", phone);
		jsonObj.put("message", message);
		
		JSONObject smsResp = new JSONObject();
		try {
			String result = WebServiceTools.getDataByUrl(url, methods, jsonObj.toString());
			smsResp = JSONObject.fromObject(result);
		} catch (Exception e) {
			smsResp = JSONObject.fromObject("{\"result\":\"0\",\"info\":\"短信发送接口异常："+e.getMessage()+"\"}");
			logger.error("短信接口异常.", e);
		}
		return smsResp;
	}

}
